#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#define WINDOW_NAME "线性混合示例"
using namespace cv;
const int g_nMaxAlphaValue = 100;
int g_nAlphaValueSlider;
double g_dAlphaValue;
double g_dBetaValue;
Mat g_srcImage1;
Mat g_srcImage2;
Mat g_dstImage;
char TrackbarName[50];
/*
相应滑动条的回调函数
*/
void on_Trackbar(int ,void*){
	g_dAlphaValue = (double)g_nAlphaValueSlider/g_nMaxAlphaValue;
	g_dBetaValue = (1.0 - g_dAlphaValue);
	addWeighted(g_srcImage1, g_dAlphaValue, g_srcImage2, g_dBetaValue, 0.0, g_dstImage);
	printf("%d\n", getTrackbarPos(TrackbarName,WINDOW_NAME));
	imshow(WINDOW_NAME, g_dstImage);

}
int main(int argc, char** argv){
	g_srcImage1 = imread("E:\\1.png");
	g_srcImage2 = imread("E:\\2.png");
	if (!g_srcImage1.data){
		printf("读取第一幅图像错误"); return -1;
	}
	if (!g_srcImage1.data){
		printf("读取第二幅图像错误"); return -1;
	}
	g_nAlphaValueSlider = 70;
	namedWindow(WINDOW_NAME,1);
	sprintf(TrackbarName,"透明值: 100");
	createTrackbar(TrackbarName, WINDOW_NAME, &g_nAlphaValueSlider, g_nMaxAlphaValue, on_Trackbar);
	on_Trackbar(g_nAlphaValueSlider, 0);
	waitKey(0);
	return 0;

}